package com.boyunv.command.example01;
/*
 *@description
 *  服务员==>Invoker  调用者
 *@author boyunv
 *@create 2023/9/7 7:38
 *@version 1.0
 */

import java.util.ArrayList;

public class Waiter {
    
    //可以持有多个命令对象
    private ArrayList<Command> commands;
    public Waiter(){
        this.commands=new ArrayList<>();
        
    }
    
    public Waiter(ArrayList<Command> commands) {
        this.commands = commands;
    }
    public void setCommands(Command command){
        this.commands.add(command);
    }
    
    //发出指令
    public  void  orderUp() throws InterruptedException {
        System.out.println("叮咚!有新的订单,厨师制作");
        for (Command command : commands) {
            if(command!=null){
                command.execute();
            }
        }
    }
}
